import asyncio

async def task(name, seconds):
    print(f"Task {name} started")
    await asyncio.sleep(seconds)
    print(f"Task {name} finished")
    return f"Result from {name}"

async def main():
    # 创建多个任务
    t1 = asyncio.create_task(task("A", 1))
    t2 = asyncio.create_task(task("B", 2))
    # 并发执行并收集结果
    results = await asyncio.gather(t1, t2)
    print(results)

loop = asyncio.get_event_loop()
loop.run_until_complete(main())  # 运行主协程[1,8](@ref)
loop.close()